<?php
/**
 * Created by 784855684@qq.com.
 * Link: https://github.com/lichtung/wshore
 * User: linzh
 * Date: 7/12/17
 * Time: 12:31 PM
 */
declare(strict_types=1);


namespace application\module\controller;


use wshore\core\Response;
use wshore\helper\Network;
use wshore\throws\NetworkException;

/**
 * Class api API接口
 * @package application\module\controller
 */
class api
{
    public function transmit(string $to, string $from, string $content)
    {
        try {
            $res = Network::getJson('http://' . WSC_SOCKET_HOST . ':' . WSC_SOCKET_PORT . '/?' .
                http_build_query([
                    'function' => 'transmit',
                    'to' => $to,
                    'from' => $from,
                    'content' => $content,
                ]));
            if ($res['status']??0) {
                Response::success('tansmit success');
            } else {
                Response::failure('transmit failed:' . ($res['message']??''));
            }
        } catch (NetworkException $exception) {
            Response::failure('transmit failed:' . $exception->getMessage());
        }
    }
}